package org.hongbo.springbootebsapi.entity.responsibility;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.Column;
import java.io.Serializable;
import java.util.List;

@Getter
@Setter
public class UserFuncEntity implements Serializable {
    private static final long serialVersionUID = -816647127390476012L;

    @JSONField(ordinal = 1)
    @Column(name = "RESPONSIBILITY_NAME")
    private String name;
    @JSONField(ordinal = 2)
    private List<UserFuncEntity> child;
    @JSONField(ordinal = 3)
    private String controller;
    @JSONField(ordinal = 4)
    private String reqMapping;
    @JSONField(ordinal = 5)
    @Column(name = "RESPONSIBILITY_ID")
    private String respId;
    @JSONField(ordinal = 6)
    private String responsibilityName;
    @JSONField(ordinal = 7)
    @Column(name = "RESPONSIBILITY_APPLICATION_ID")
    private String respApplId;
    @JSONField(ordinal = 8)
    @Column(name = "PROMPT")
    private String functionPrompt;
    @JSONField(ordinal = 9)
    private String params;

    public UserFuncEntity(){
        super();
    }

    public UserFuncEntity(String name,List<UserFuncEntity> child,String controller,String reqMapping,String respId,String respApplId,String params){
        super();
        this.name = name;
        this.child = child;
        this.controller = controller;
        this.reqMapping = reqMapping;
        this.respId = respId;
        this.respApplId = respApplId;
        this.params = params;
    }

    public String getController() {
        if(getReqMapping()!=null && getRespApplId()!=null && getRespId()!=null){
            return "/init_responsiblity?req_mapping="+getReqMapping()+"&resp_id="+getRespId()+"&resp_appl_id="+getRespApplId()+"&params="+getParams();
        }else{
            return controller;
        }
    }

    public void setName(String name) {
        if(name.startsWith("B")){
            name = name.substring(10);
        }
        this.name = name;
    }

    @Override
    public String toString(){
        return JSON.toJSONString(this);
    }

}
